package com.fzrskj.cloud.free.api;

import com.fzrskj.cloud.free.core.enums.PayWayEnum;
import com.fzrskj.cloud.free.core.utils.CloudContextUtils;
import com.fzrskj.cloud.free.dic.utils.DicParamUtils;
import com.fzrskj.cloud.free.thridparty.pay.wechat.WechatPay;
import net.sf.json.JSONObject;

import java.text.ParseException;

public class API {
    /***↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓支付↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓***/
    //在线充值
    public String OnlineRecharge(int rechargeType, String param) {
        String result = "";
        switch (rechargeType) {
            case 1:
                result = this.alipayRecharge(param);
                break;
            case 2:
                ShenpayAPI sftpay = new ShenpayAPI();
                result = sftpay.sftpay(param);
                break;
            case 3:
                result = WechatPay.create(param);
                break;
            default:
                JSONObject obj = new JSONObject();
                obj.put("code", "-1");
                obj.put("message", "无法识别的在线充值代码");
                result = obj.toString();
                break;
        }
        return result;
    }

    //支付宝支付(自己帐户和公司帐户)
    public String alipayRecharge(String param) {
        AlipayAPI alipayAPI = new AlipayAPI();
        String result = "";
        String alipayacways = DicParamUtils.getParamValue(PayWayEnum.ALIPAY.getKey());
        int alipayac_way = Integer.valueOf(alipayacways);
        switch (alipayac_way) {
            case 1:
                result = alipayAPI.alipay(param, CloudContextUtils.getAgentId());
                break;
            case 2:
                result = alipayAPI.alipayWiniis(param);
                break;
            case 99:
                result = alipayAPI.alipay(param, DicParamUtils.getLastSelfPayParent(PayWayEnum.ALIPAY.getKey(), CloudContextUtils.getAgentId()));
                break;
            default:
                JSONObject obj = new JSONObject();
                obj.put("code", "-1");
                obj.put("message", "无法识别的在线充值代码");
                result = obj.toString();
                break;
        }
        alipayAPI = null;

        return result;
    }
    /***↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑支付↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑***/

    /***↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓短信↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓***/
    public String SendSms(int smsType, String param) {
        String result = "";
        switch (smsType) {
            case 1:
                /**
                 * 点集科技.
                 */
                DdkjSmsAPI sms = new DdkjSmsAPI();
                result = sms.dianjiSms(param);
                break;
            case 2:
                /**
                 * 商讯中国
                 */
                SmsAPI sms139000API = new Sms139000API();
                result = sms139000API.send(param);
                break;
            case 99:
                /**
                 * 自定义
                 */
                SmsAPI smsDiyAPI = new SmsDiyAPI();
                result = smsDiyAPI.send(param);
                break;
            default:
                JSONObject obj = new JSONObject();
                obj.put("code", "-1");
                obj.put("message", "无法识别运营商！");
                result = obj.toString();
                break;
        }
        return result;
    }

    /***↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑短信↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑***/

    //测试
    public static void main(String[] args) throws ParseException {
//		API api=new API();
//		String result=api.regDomain("G1479200131522","1");
        //	String result=api.syncRegion("{\"uid\":10000,\"uname\":\"lsyfg\"}", 2);
//		System.out.println(result);	
    }
}

